package com.happycat.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.happycat.ResponseHeaderModel;
import com.happycat.SysContants;

@Component
public class HappyCatAuthenticationEntryPoint implements AuthenticationEntryPoint{

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException, ServletException {
		ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseHeaderModel.setMessage("访问接口失败！"+authException.getMessage());
		response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
		response.getOutputStream().write(JSON.toJSONString(responseHeaderModel).getBytes());
		
	}
	
}
